<template>
  <div id="recordIndex">
    <el-row>
      <!-- 表格查询条件 -->
      <el-col :span="24">
        <el-form :inline="true" ref="stationForm" :model="queryForm">
          <el-form-item>
            <el-input v-model="queryForm.name" placeholder="物资名称/编号"></el-input>
          </el-form-item>
          <el-form-item>
            <el-input v-model="queryForm.assificationName" placeholder="物资分类"></el-input>
          </el-form-item>
          <el-form-item>
            <el-input v-model="queryForm.modelName" placeholder="物资型号"></el-input>
          </el-form-item>
          <el-form-item>
            <gd_param type="select"
                      paramCode="unit"
                      placeholder="计量单位"
                      v-model="queryForm.uniCode" />
          </el-form-item>
          <el-form-item>
            <el-input v-model="queryForm.warehouseName" placeholder="仓库名称"></el-input>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" icon="el-icon-search" @click="getTableDatas()">查询</el-button>
            <el-button @click="resetQueryForm" icon="el-icon-refresh-right">重置</el-button>
          </el-form-item>
        </el-form>
      </el-col>
    </el-row>
    <el-row>
      <!-- 数据表格 -->
      <el-col :span="24">
        <el-row>
          <el-col :span="24">
            <el-button type="primary" icon="el-icon-plus" @click="dialog.isEdit=false;dialog.saveOrEditDiv=true">新增物资</el-button>
            <el-popconfirm title="这是一段内容确定删除吗？" @confirm="moreDeletes">
              <el-button slot="reference" type="danger" icon="el-icon-delete">批量删除</el-button>
            </el-popconfirm>
          </el-col>
        </el-row>
        <el-row style="margin-top:10px;">
          <el-col :span="24">
            <el-table :data="tableData" border style="width: 100%" @selection-change="tableDataSelected">
              <el-table-column type="selection" width="55"></el-table-column>
              <el-table-column prop="code" label="编号"></el-table-column>
              <el-table-column prop="name" label="物资名称"></el-table-column>
              <el-table-column prop="assificationName" label="物资分类"></el-table-column>
              <el-table-column prop="modelName" label="物资型号">
                <template slot-scope="scope">
                  <span v-if="scope.row.modelName">{{ scope.row.modelName }}</span>
                  <el-tag v-else type="danger">未关联型号</el-tag>
                </template>
              </el-table-column>
              <el-table-column prop="warehouseName" label="所在仓库"></el-table-column>
              <el-table-column prop="wmsCount" label="台账数量" width="120">
                <template slot-scope="scope">
                  <el-tag type="success">{{ scope.row.wmsCount + scope.row.uniName}}</el-tag>
                </template>
              </el-table-column>
              <el-table-column label="物资状态" width="120">
                <template slot-scope="scope">
                  <el-tag v-if="scope.row.isDelete!=1&&scope.row.wmsCount>0" type="success">在库</el-tag>
                  <el-tag v-if="scope.row.isDelete!=1&&scope.row.wmsCount==0" type="warning">无库存</el-tag>
                  <el-tag v-if="scope.row.isDelete==1"type="danger">失效</el-tag>
                </template>
              </el-table-column>
              <el-table-column fixed="right" label="操作" align="center" width="180">
                <template slot-scope="scope">
                  <el-button @click="rowShow(scope.row)" size="small" icon="el-icon-search" circle title="查看"></el-button>
                  <el-button @click="rowEdit(scope.row)" type="primary" size="small" icon="el-icon-edit" circle title="编辑"></el-button>
                  <el-button @click="rowDelete(scope.row)" type="danger" icon="el-icon-delete" size="small" circle title="删除"></el-button>
                  <el-dropdown>
                    <span class="el-dropdown-link"><i class="el-icon-arrow-down el-icon--right"></i></span>
                    <el-dropdown-menu slot="dropdown">
                      <el-dropdown-item><span @click="rowOutBound(scope.row)">物资出库</span></el-dropdown-item>
                      <el-dropdown-item><span @click="rowLife(scope.row)">生命周期记录</span></el-dropdown-item>
                    </el-dropdown-menu>
                  </el-dropdown>
                </template>
              </el-table-column>
            </el-table>
            <el-pagination
              @size-change="tableSizeChange"
              @current-change="tableCurrentChange"
              :current-page="pageData.page"
              :page-sizes="[10, 20, 40, 100]"
              :page-size="pageData.size"
              layout="total, sizes, prev, pager, next, jumper"
              :total="pageData.total"
            ></el-pagination>
          </el-col>
        </el-row>
      </el-col>
    </el-row>

    <!-- 添加或修改-业务弹窗 -->
    <el-dialog
      :title="dialog.isEdit == true ? '编辑台账' : '新增物资'"
      :visible.sync="dialog.saveOrEditDiv"
      width="80%"
      :show-close="false"
      :destroy-on-close="true"
      :close-on-click-modal="false"
    >
    <el-tabs v-model="activeName">
        <el-tab-pane label="物资基础信息" name="1">

        </el-tab-pane>
        <el-tab-pane label="附属信息" name="2">

        </el-tab-pane>
      </el-tabs>
      <el-row v-if="activeName=='1'" >
        <el-form ref="saveOrEditDataForm" :rules="saveOrEditDataFormRules" :model="saveOrEditData.record" label-width="80px">
          <el-row>
            <el-col :span="12">
              <el-form-item label="物资名称" prop="name">
                <el-input show-word-limit v-model="saveOrEditData.record.name" placeholder="请输入物资名称" maxlength="20"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item v-if="dialog.isEdit==false" label="入库仓库" prop="warehouseID">
                <el-select style="width: 100%" v-model="saveOrEditData.record.warehouseID" @change="warehouseSelectChange" filterable  clearable placeholder="请选择入库仓库">
                  <el-option
                    v-for="item in warehouseListData"
                    :key="item.warehouseID"
                    :label="item.name"
                    :value="item.warehouseID">
                  </el-option>
                </el-select>
              </el-form-item>
              <el-form-item v-if="dialog.isEdit==true" label="所在仓库" prop="warehouseID">
                <el-input
                  v-model="saveOrEditData.record.warehouseName"
                  :disabled="true">
                </el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="物资分类" prop="assificationID">
                <el-select style="width: 100%" v-model="saveOrEditData.record.assificationID" @change="wmsTypeChange" filterable clearable placeholder="请选择物资分类">
                  <el-option
                    v-for="item in classificationListData"
                    :key="item.classificationID"
                    :label="item.name"
                    :value="item.classificationID">
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="物资型号" prop="modelID">
                <el-select style="width: 100%" v-model="saveOrEditData.record.modelID" @change="wmsTypeModelChange" filterable clearable placeholder="先选择分类后再选择型号">
                  <el-option
                    v-for="item in modelListData"
                    :key="item.modelID"
                    :label="item.name"
                    :value="item.modelID">
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="计量单位" prop="uniCode">
                <gd_param type="select"
                          paramCode="unit"
                          placeholder="请选择计量单位"
                          @selectChange="unitTypeChange"
                          v-model="saveOrEditData.record.uniCode" />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item v-if="dialog.isEdit == false" label="入库数量" prop="wmsCount">
                <el-input type="number" show-word-limit v-model="saveOrEditData.record.wmsCount" placeholder="请输入入库数量" maxlength="10"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item v-if="dialog.isEdit == false" label="入库人">
                <el-select style="width: 100%" v-model="saveOrEditData.inbound.userID" @change="inUserSelectChange" filterable clearable placeholder="请选择入库处理人">
                  <el-option
                    v-for="item in userListData"
                    :key="item.staffID"
                    :label="item.name"
                    :value="item.staffID">
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="备注" prop="comment">
                <el-input
                  show-word-limit
                  maxlength="150"
                  type="textarea"
                  :autosize="{ minRows: 2, maxRows: 4 }"
                  placeholder="如需备注输入描述"
                  v-model="saveOrEditData.record.comment"
                ></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="8">
              <el-form-item label="物资照片1">
                <gd_file v-if="dialog.isEdit == false" @uploadSuccess="recordFile1UploadSuccess" />
                <gd_file
                  v-else
                  :fileID="saveOrEditData.record.fileID1"
                  @uploadSuccess="recordFile1UploadSuccess"
                />
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="物资照片2">
                <gd_file v-if="dialog.isEdit == false" @uploadSuccess="recordFile2UploadSuccess" />
                <gd_file
                  v-else
                  :fileID="saveOrEditData.record.fileID2"
                  @uploadSuccess="recordFile2UploadSuccess"
                />
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="物资照片3">
                <gd_file v-if="dialog.isEdit == false" @uploadSuccess="recordFile3UploadSuccess" />
                <gd_file
                  v-else
                  :fileID="saveOrEditData.record.fileID3"
                  @uploadSuccess="recordFile3UploadSuccess"
                />
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
      </el-row>

      <el-row v-if="activeName=='2'" >
        <el-button type="primary" @click="addFieldsInfo" :loading="formLoading">添加属性</el-button>
        <el-form label-width="80px">
          <el-row style="margin-top: 10px" v-for="(item,index) in saveOrEditData.fieldsInfoList" :key="index">
            <el-col :span="12">
              <el-form-item label="属性-名称" prop="fname">
                <el-input show-word-limit v-model="saveOrEditData.fieldsInfoList[index].name" placeholder="请输入属性名称" maxlength="20"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="10">
              <el-form-item label="属性-值" prop="fvalue">
                <el-input show-word-limit v-model="saveOrEditData.fieldsInfoList[index].vals" placeholder="请输入属性值" maxlength="20"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="2" style="box-sizing: border-box;padding-left: 10px">
              <el-button @click="removeFieldsInfo(item.uid)" type="danger" title="点击移除当前行" icon="el-icon-delete" circle></el-button>
            </el-col>
          </el-row>
        </el-form>
      </el-row>
      <!-- 按钮组 -->
      <div style="margin-top: 10px">
        <el-button type="primary" @click="submitSaveOrEdit" :loading="formLoading">{{ dialog.isEdit == false ? '保存' : '确认修改' }}</el-button>
        <el-button
          @click="
							dialog.saveOrEditDiv = false;
							resetAddOrEditOrShowForm();
						"
        >
          取消
        </el-button>
      </div>

    </el-dialog>

    <!-- 详情弹窗 -->
    <el-dialog
      title="台账详情"
      :visible.sync="dialog.showDiv"
      width="90%"
      :show-close="false"
      :destroy-on-close="true"
      :close-on-click-modal="false"
    >
      <recordInfo :recordID="showData.record.recordID"  v-if="dialog.showDiv"/>
      <el-row style="margin-top: 10px">
        <el-button
          @click="
							dialog.showDiv = false;
							resetAddOrEditOrShowForm();
						"
        >
          关闭
        </el-button>
      </el-row>
    </el-dialog>

    <!-- 生命周期弹窗 -->
    <el-dialog
      title="物资生命周期记录"
      :visible.sync="dialog.life"
      width="60%"
      :show-close="false"
      :destroy-on-close="true"
      :close-on-click-modal="false"
    >
      <wmsLifeInfo :recordID="showData.record.recordID"  v-if="dialog.life"/>
      <el-row style="margin-top: 10px">
        <el-button
          @click="
							dialog.life = false;
							resetAddOrEditOrShowForm();
						"
        >
          关闭
        </el-button>
      </el-row>
    </el-dialog>

    <!-- 出库弹窗 -->
    <el-dialog
      title="物资出库"
      :visible.sync="dialog.outbound"
      width="60%"
      :show-close="false"
      :destroy-on-close="true"
      :close-on-click-modal="false"
    >
      <el-form ref="outboundForm" :rules="outboundFormRules" :model="saveOrEditData.record" label-width="80px">
        <el-row>
          <el-col :span="8">
            <el-form-item label="物资名称" prop="name">
              <el-input show-word-limit v-model="saveOrEditData.record.name" :disabled="true"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="出库数量" prop="wmsCount">
              <el-input show-word-limit v-model="saveOrEditData.record.wmsCount" placeholder="请输入出库数量" type="number" maxlength="10"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="出库人">
              <el-select style="width: 100%" v-model="saveOrEditData.outbound.userID" @change="outUserSelectChange" filterable clearable placeholder="请选择出库处理人">
                <el-option
                  v-for="item in userListData"
                  :key="item.staffID"
                  :label="item.name"
                  :value="item.staffID">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <!-- 按钮组 -->
      <div style="margin-top: 10px">
        <el-button type="primary" @click="doOutBound" :loading="formLoading">确认出库</el-button>
        <el-button
          @click="
							dialog.outbound = false;
							resetAddOrEditOrShowForm();
						"
        >
          取消
        </el-button>
      </div>
    </el-dialog>

  </div>
</template>

<script>
import gd_param from "@/components/mycomponents/gd_param.vue";
import * as axiosAPI from '@/api/wms/record.js';
import gd_file from "@/components/mycomponents/gd_file.vue";

import * as wmsTypeAPI from '@/api/wms/classification.js';
import * as wmsTypeModelAPI from '@/api/wms/classificationModel.js';
import * as warehouseAPI from '@/api/wms/warehouse.js';
import * as staffAPI from '@/api/staff.js';

import recordInfo from "@/components/wms/record/recordInfo";
import wmsLifeInfo from "@/components/wms/record/wmsLifeInfo";
export default {
  name: 'recordIndex',
  components:{gd_file, gd_param,recordInfo,wmsLifeInfo},
  data() {
    return {
      activeName:"1",
      //查询表单数据
      queryForm: {
        name: null,
        assificationName: null,
        modelName: null,
        uniCode: null,
        warehouseName: null
      },
      //表格数据
      tableData: [],
      // 仓库列表
      warehouseListData:[],
      // 物资分类
      classificationListData:[],
      // 物资型号
      modelListData:[],
      // 用户列表
      userListData:[],
      //主表-分页数据
      pageData: {
        page: 1,
        size: 10,
        total: 0
      },
      //当前表格复选数据
      nowTableSelected: [],
      //弹窗状态
      dialog: {
        isEdit: false,
        saveOrEditDiv: false,
        showDiv: false,
        life: false,
        outbound: false
      },
      //添加或编辑表单数据
      saveOrEditData: {
        record:{ // 物资信息
          recordID: null,
          comment: null,
          name: null,
          code: null,
          assificationID: null,
          assificationName: null,
          modelID: null,
          modelName: null,
          uniCode: null,
          uniName: null,
          wmsCount: 0,
          warehouseID: null,
          warehouseName: null,
          fileID1:null,
          fileUrl1:null,
          fileID2:null,
          fileUrl2:null,
          fileID3:null,
          fileUrl3:null
        },
        inbound:{// 入库信息
          userID:null,
          userName:null
        },
        outbound:{ // 出库信息
          userID:null,
          userName:null
        },
        fieldsInfoList:[] // 附加属性集合
      },
      //添加编辑表单-检验
      saveOrEditDataFormRules:{
        name: { required: true, message: '请输入物资名称', trigger: 'blur' },
        warehouseID: { required: true, message: '请选择仓库', trigger: 'change' },
        assificationID: { required: true, message: '请选择物资分类', trigger: 'change' },
        uniCode: { required: true, message: '请选择计量单位', trigger: 'change' },
        wmsCount: { required: true, message: '请输入入库数量', trigger: 'blur' },
        userID: { required: true, message: '请选择入库操作人', trigger: 'change' }
      },
      // 出库表单校验
      outboundFormRules:{
        wmsCount: { required: true, message: '请输入出库数量', trigger: 'blur' },
      },
      //展示表单数据
      showData: {
        record:{ // 物资信息
          recordID: null,
          comment: null,
          name: null,
          code: null,
          assificationID: null,
          assificationName: null,
          modelID: null,
          modelName: null,
          uniCode: null,
          uniName: null,
          wmsCount: 0,
          warehouseID: null,
          warehouseName: null,
          fileID1:null,
          fileUrl1:null,
          fileID2:null,
          fileUrl2:null,
          fileID3:null,
          fileUrl3:null
        },
        fieldsInfoList:[] // 附加属性集合
      },
      //表单加载值
      formLoading: false
    };
  },
  mounted() {
    this.initWarehouseListData();
    this.initClassificationListData();
    this.initUserListData();
    this.getTableDatas();
  },
  methods: {
    // 查询用户列表
    initUserListData(){
      var _this = this;
      staffAPI.list({"name":null,"tellNumber":null})
        .then(function(res){
          if(res.code == "0000"){
            _this.userListData = res.data;
          }
        });
    },
    // 查询分类
    initClassificationListData(){
      var _this = this;
      wmsTypeAPI.list()
        .then(function(res){
          if(res.code == "0000"){
            _this.classificationListData = res.data;
          }
        });
    },
    // 查询型号
    initModelListData(id){
      var _this = this;
      if(id){
        wmsTypeModelAPI.list({"classificationID":id})
          .then(function(res){
            if(res.code == "0000"){
              _this.modelListData = res.data;
            }
          });
      }

    },
    // 查询仓库列表
    initWarehouseListData(){
      var _this = this;
      warehouseAPI.list()
        .then(function(res){
          if(res.code == "0000"){
             _this.warehouseListData = res.data;
          }
        });
    },
    //查询表格数据
    getTableDatas() {
      let _this = this;
      axiosAPI.pages(_this.queryForm, _this.pageData)
        .then(function(response) {
          console.log(response);
          if (response.code == '0000') {
            _this.tableData = response.data.rows;
            _this.pageData.total = response.data.total;
          }
        });
    },
    //重置查询条件表单
    resetQueryForm() {
      this.queryForm = {
        name: null,
        assificationName: null,
        modelName: null,
        uniCode: null,
        warehouseName: null
      };
      this.getTableDatas();
    },
    //重置添加、编辑、展示表单
    resetAddOrEditOrShowForm() {
      this.showData = {
        record:{ // 物资信息
          recordID: null,
          comment: null,
          name: null,
          code: null,
          assificationID: null,
          assificationName: null,
          modelID: null,
          modelName: null,
          uniCode: null,
          uniName: null,
          wmsCount: 0,
          warehouseID: null,
          warehouseName: null,
          fileID1:null,
          fileUrl1:null,
          fileID2:null,
          fileUrl2:null,
          fileID3:null,
          fileUrl3:null
        },
        fieldsInfoList:[] // 附加属性集合
      };
      this.saveOrEditData = {
        record:{ // 物资信息
          recordID: null,
          comment: null,
          name: null,
          code: null,
          assificationID: null,
          assificationName: null,
          modelID: null,
          modelName: null,
          uniCode: null,
          uniName: null,
          wmsCount: 0,
          warehouseID: null,
          warehouseName: null,
          fileID1:null,
          fileUrl1:null,
          fileID2:null,
          fileUrl2:null,
          fileID3:null,
          fileUrl3:null
        },
        inbound:{// 入库信息
          userID:null,
          userName:null
        },
        outbound:{ // 出库信息
          userID:null,
          userName:null
        },
        fieldsInfoList:[] // 附加属性集合
      };
    },
    //提交-添加、编辑表单
    submitSaveOrEdit() {
      let _this = this;
      this.$refs.saveOrEditDataForm.validate(valid => {
        if (valid) {
          this.formLoading = true;
          let _this = this;
          if(_this.dialog.isEdit == true){// 编辑

            axiosAPI.update(_this.saveOrEditData)
              .then(function(res) {
                if (res.code == '0000') {
                  _this.dialog.saveOrEditDiv = false;
                  _this.resetAddOrEditOrShowForm();
                  _this.formLoading = false;
                  _this.getTableDatas();
                } else {
                  _this.formLoading = false;
                }
              });

          }else{ // 添加
            axiosAPI.add(_this.saveOrEditData)
              .then(function(res) {
                if (res.code == '0000') {
                  _this.dialog.saveOrEditDiv = false;
                  _this.resetAddOrEditOrShowForm();
                  _this.formLoading = false;
                  _this.getTableDatas();
                } else {
                  _this.formLoading = false;
                }
              });
          }
        }
      });
    },
    //提交-删除
    submitDelete(ids){
      let _this = this;
      axiosAPI.deletes(ids)
        .then(res => {
          if (res.code == '0000') {
            _this.getTableDatas();
          }
        });
    },
    //分页条目数切换
    tableSizeChange(size) {
      this.pageData.size = size;
      this.getTableDatas();
    },
    //页码切换
    tableCurrentChange(page) {
      this.pageData.page = page;
      this.getTableDatas();
    },
    //行-查看
    rowShow(data) {
      this.showData.record = JSON.parse(JSON.stringify(data));
      this.dialog.showDiv = true;
    },
    //行-编辑
    rowEdit(data) {
      let _this = this;
      axiosAPI.getByID(data.recordID)
        .then(function(res){
         if(res.code == "0000"){
           _this.dialog.saveOrEditDiv = true;
           _this.saveOrEditData.record = res.data.record;
           _this.initModelListData(_this.saveOrEditData.record.assificationID);
           _this.saveOrEditData.fieldsInfoList = res.data.fieldsInfoList;
           _this.dialog.isEdit = true;
         }
      })

    },
    //行-删除
    rowDelete(data) {
      this.$confirm('确定要删除这行数据吗?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.submitDelete(data.recordID);
      });
    },
    //点击批量删除
    moreDeletes() {
      if(this.nowTableSelected.length<=0){
        this.$notify.warning({
          title: '删除提示',
          message: '请至少选择一条数据再删除'
        });
        return;
      }
      let ids = '';

      for (var i in this.nowTableSelected) {
        ids += this.nowTableSelected[i].recordID + ',';
      }

      ids = ids.substring(0, ids.length - 1);

      //调用删除
      this.submitDelete(ids);
    },
    //表格批量选择
    tableDataSelected(data){
      this.nowTableSelected = data;
    },
    // 所属仓库选择
    warehouseSelectChange(data){
      if(data!=""){
        var resData = null;
        for(var i in this.warehouseListData){
          if(this.warehouseListData[i].warehouseID == data){
            resData = this.warehouseListData[i];
            break;
          }
        }
        this.saveOrEditData.record.warehouseID = resData.warehouseID;
        this.saveOrEditData.record.warehouseName = resData.name;
      }else{
        this.saveOrEditData.record.warehouseID = null;
        this.saveOrEditData.record.warehouseName = null;
      }
    },
    // 物资分类选择
    wmsTypeChange(data){
      if(data!=""){
        var resData = null;
        for(var i in this.classificationListData){
          if(this.classificationListData[i].classificationID == data){
            resData = this.classificationListData[i];
            break;
          }
        }
        this.saveOrEditData.record.assificationID = resData.classificationID;
        this.saveOrEditData.record.assificationName = resData.name;

        // 查询型号
        this.initModelListData(resData.classificationID);
      }else{
        this.saveOrEditData.record.assificationID = null;
        this.saveOrEditData.record.assificationName = null;

        this.saveOrEditData.record.modelID = null;
        this.saveOrEditData.record.modelName = null;

        this.modelListData = [];
      }
    },
    // 物资型号选择
    wmsTypeModelChange(data){
      if(data!=""){
        var resData = null;
        for(var i in this.modelListData){
          if(this.modelListData[i].modelID == data){
            resData = this.modelListData[i];
            break;
          }
        }
        this.saveOrEditData.record.modelID = resData.modelID;
        this.saveOrEditData.record.modelName = resData.name;

        this.saveOrEditData.record.uniCode = resData.uniCode;
        this.saveOrEditData.record.uniName = resData.uniName;
      }else{
        this.saveOrEditData.record.modelID = null;
        this.saveOrEditData.record.modelName = null;

        this.saveOrEditData.record.uniCode = null;
        this.saveOrEditData.record.uniName = null;
      }
    },
    // 出库人选择
    outUserSelectChange(data){
      if(data!=""){
        var resData = null;
        for(var i in this.userListData){
          if(this.userListData[i].staffID == data){
            resData = this.userListData[i];
            break;
          }
        }
        this.saveOrEditData.outbound.userID = resData.staffID;
        this.saveOrEditData.outbound.userName = resData.name;
      }else{
        this.saveOrEditData.outbound.userID = null;
        this.saveOrEditData.outbound.userName = null;
      }
    },
    // 入库人选择切换
    inUserSelectChange(data){
      if(data!=""){
        var resData = null;
        for(var i in this.userListData){
          if(this.userListData[i].staffID == data){
            resData = this.userListData[i];
            break;
          }
        }
        this.saveOrEditData.inbound.userID = resData.staffID;
        this.saveOrEditData.inbound.userName = resData.name;
      }else{
        this.saveOrEditData.inbound.userID = null;
        this.saveOrEditData.inbound.userName = null;
      }
    },
    // 计量单位切换
    unitTypeChange(data){
      if(data == undefined){
        this.saveOrEditData.record.uniCode = null;
        this.saveOrEditData.record.uniName = null;
      }else{
        this.saveOrEditData.record.uniCode = data.dataValue;
        this.saveOrEditData.record.uniName = data.dataName;
      }
    },
    // 图片上传切换1
    recordFile1UploadSuccess(data){
      if(data.length==0){
        this.saveOrEditData.record.fileID1 = null;
        this.saveOrEditData.record.fileUrl1 = null;
      }else{
        this.saveOrEditData.record.fileID1 = data[0].id;
        this.saveOrEditData.record.fileUrl1 = data[0].url;
      }
    },
    // 图片上传切换2
    recordFile2UploadSuccess(data){
      if(data.length==0){
        this.saveOrEditData.record.fileID2 = null;
        this.saveOrEditData.record.fileUrl2 = null;
      }else{
        this.saveOrEditData.record.fileID2 = data[0].id;
        this.saveOrEditData.record.fileUrl2 = data[0].url;
      }
    },
    // 图片上传切换3
    recordFile3UploadSuccess(data){
      if(data.length==0){
        this.saveOrEditData.record.fileID3 = null;
        this.saveOrEditData.record.fileUrl3 = null;
      }else{
        this.saveOrEditData.record.fileID3 = data[0].id;
        this.saveOrEditData.record.fileUrl3 = data[0].url;
      }
    },
    // 添加新的属性
    addFieldsInfo(){
      var tempData = {
        uid:this.saveOrEditData.fieldsInfoList.length,
        name:null,
        vals:null
      }
      this.saveOrEditData.fieldsInfoList.push(tempData);
    },
    // 移除属性行
    removeFieldsInfo(uid){
        var idd = 0;
        for(var i in this.saveOrEditData.fieldsInfoList){
          if(this.saveOrEditData.fieldsInfoList[i].uid == uid){
             idd = i;
             break;
          }
        }
      this.saveOrEditData.fieldsInfoList.splice(idd,1);
    },
    // 行-查看生命周期
    rowLife(data){
      this.showData.record = JSON.parse(JSON.stringify(data));
      this.dialog.life = true;
    },
    // 物资出库
    rowOutBound(data){
      this.saveOrEditData.record = JSON.parse(JSON.stringify(data));
      this.dialog.outbound = true;
    },
    // 物资出库提交
    doOutBound(){
      let _this = this;
      this.$refs.outboundForm.validate(valid => {
        if (valid) {
          _this.formLoading = true;
          axiosAPI.outRecord(_this.saveOrEditData)
            .then(function(res){
               if(res.code == "0000"){
                 _this.dialog.outbound = false;
                 _this.formLoading = false;
                 _this.getTableDatas();
               }
            });
        }
      });

    }

  }
};
</script>

<style scoped></style>
